﻿using DotNetFunctionDemo.CommonLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DotNetFunctionDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            ReflectionClass objr = new ReflectionClass();
            var minfos = ReflectionHelp.PrintMemberInfo<ReflectionClass>(objr);
            return;


            //Stopwatch timer = new Stopwatch();
            //timer.Start();
            //for (int i = 0; i < 100000000; i++)
            //{
            //    Student stu = new Student();
            //}

            //timer.Stop();
            //Console.WriteLine(timer.Elapsed.TotalSeconds);

            //使用老赵的工具测试
            int iterationCount = 1000000;
            //CodeTimer.Time("native new object", iterationCount, () => {
            //    Student stu = new Student();
            //});
            //CodeTimer.Time("reflection create object", iterationCount, () => {
            //    Student stu = ObjectMapper.CreateInstance<Student>();
            //});
            //CodeTimer.Time("Activator create object", iterationCount, () => {
            //    Student stu = ObjectMapper.CreateInstanceByActivator<Student>();
            //});

            //DemoEmit.CopyObjectByEmit();
            CodeTimer.Time("native add method", iterationCount, () =>
            {
                var sum = DemoEmit.Add(1, 3);
            });
            CodeTimer.Time("Emit add method", iterationCount, () => {
                var sum = DemoEmit.AddEmit(1, 3);
            });
            Student stu1 = new Student();
            stu1.Name = "first name native";
            var obj = DemoEmit.genAssembly<Student>(stu1);
            Console.ReadKey();
            return;

            CodeTimer.Time("native copy object", iterationCount, () =>
            {
                Student stu = new Student();
                stu.Name = "first name native";

                StudentOther stuOther = new StudentOther();
                stuOther.Name = stu.Name;
            });

            CodeTimer.Time("copy object by lambda", iterationCount, () =>
            {
                Student stu = new Student();
                stu.Name = "first name lambda";

                StudentOther stuOther = ObjectMapper.CopyObjectByReflection<Student, StudentOther>(stu);
            });
            CodeTimer.Time("copy object by expression", iterationCount, () =>
            {
                Student stu = new Student();
                stu.Name = "first name expression";

                StudentOther stuOther = ObjectMapper.copyObj(stu);
                //Console.WriteLine(stuOther);
                //StudentOther stuOther = ObjectMapper.CopyObjectByExpression(stu);
            });


            Console.ReadKey();

        }
    }
}
